#include <REGX52.H>
#include "key.h"
#include "delay.h"

/**
  * @brief  获取独立按键键码
  * @param  无
  * @retval 按下按键的键码，范围0~4，无按键按下时返回0
  */
unsigned char Key(void)
{
	unsigned char keyNumber = 0;
	
	if(P3_1 == 0){
		Delay(10);				//按键按下消抖
		while(P3_1 == 0);		//检测松手，没有松手一直循环
		Delay(10);				//按键松开消抖
		keyNumber = 1;
	}
	
	if(P3_0 == 0){
		Delay(10);				//按键按下消抖
		while(P3_0 == 0);		//检测松手，没有松手一直循环
		Delay(10);				//按键松开消抖
		
		keyNumber = 2;
	}
		
	if(P3_2 == 0){
		Delay(10);				//按键按下消抖
		while(P3_2 == 0);		//检测松手，没有松手一直循环
		Delay(10);				//按键松开消抖
		
		keyNumber = 3;
	}
		
	if(P3_3 == 0){
		Delay(10);				//按键按下消抖
		while(P3_3 == 0);		//检测松手，没有松手一直循环
		Delay(10);				//按键松开消抖
		
		keyNumber = 4;
	}
	
	return keyNumber;
}
